package com.doit.day02

object _06_特质 {
  def main(args: Array[String]): Unit = {

    val dog: NiuBiDog = new NiuBiDog

    //特质的动态混入  可以给某一个对象，单独混入接口
    val xiaoTianDog: NiuBiDog with CanFly= new NiuBiDog with CanFly {
      override def fly(): Unit = println("我跟着小二，飞来飞去")
    }

    xiaoTianDog.fly()

    val person: Person = new Person {
      override val id: Int = 1

      override def add(a: Int, b: Int): Int = a + b

      var age = 18

    }

    println(person.age)




  }
}

//继承也好，实现也好，第一个都是extends，后面都是用的with
class NiuBiDog() extends CanEat with CanJump {
  override val gender: String = "male"

  override def eatElephant(): Unit = println("俺能吃大象")

  override def jump(): Unit = println("纵身一跃，摔个大跟头！！！")
}


abstract class Person(){
  //定义抽象属性
  val id:Int
  var age:Int
  //定义具体的成员属性
  val name:String = "zss"
  //抽象方法
  def add(a:Int,b:Int):Int
  //具体的方法
  def plus(a:Int,b:Int)={
    a+b
  }
}

